/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.carrito.jsf.bo;

import com.carrito.jdbc.dao.ImpAlumno;
import com.carrito.jsf.bean.BeanAlumno;
import com.carrito.jsf.persistence.Alumno;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;

/**
 *
 * @author oscarc
 */
public class AlumnoImplBO implements AlumnoBO {
    
    @Autowired
    private ImpAlumno alumnoDAO;//mediante inyeccion de dependencias

    @Override
    public void insert(BeanAlumno obj) {
        Alumno alumno = new Alumno();
        alumno.setCodigo(obj.getCodigo());
        alumno.setMatricula(obj.getMatricula());
        alumno.setNombre(obj.getNombre());
        alumno.setSexo(obj.getSexo());
        getAlumnoDAO().insert(alumno);
    }
    
    @Override
    public void delete(BeanAlumno obj) {
        Alumno alumno = new Alumno();
        alumno.setCodigo(obj.getCodigo());
        alumno.setMatricula(obj.getMatricula());
        alumno.setNombre(obj.getNombre());
        alumno.setSexo(obj.getSexo());
        getAlumnoDAO().delete(alumno);
    }
    
    @Override
    public void update(BeanAlumno obj) {
        Alumno alumno = new Alumno();
        alumno.setCodigo(obj.getCodigo());
        alumno.setMatricula(obj.getMatricula());
        alumno.setNombre(obj.getNombre());
        alumno.setSexo(obj.getSexo());
        getAlumnoDAO().update(alumno);
    }
    
    @Override
    public List<BeanAlumno> getAll() {
        List<BeanAlumno> lista = new ArrayList<BeanAlumno>();
        for (Alumno obj : alumnoDAO.getAll()) {
            BeanAlumno bean = new BeanAlumno();
            bean.setCodigo(obj.getCodigo());
            bean.setMatricula(obj.getMatricula());
            bean.setNombre(obj.getNombre());
            bean.setSexo(obj.getSexo());
            lista.add(bean);
        }
        return lista;
    }

    /**
     * @return the alumnoDAO
     */
    public ImpAlumno getAlumnoDAO() {
        return alumnoDAO;
    }

    /**
     * @param alumnoDAO the alumnoDAO to set
     */
    public void setAlumnoDAO(ImpAlumno alumnoDAO) {
        this.alumnoDAO = alumnoDAO;
    }
}
